<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head>

<title>登录后台</title>
<link href="${pageContext.request.contextPath}/css/admin.css"	rel="stylesheet" type="text/css" />

<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-3.4.1.js"></script>
<script language="javascript">
	function check() {
		var login_username = document.getElementById("uname");
		var login_password = document.getElementById("upwd");
		if (login_username.value == "") {
			alert("用户名不能为空！请重新填入！");
			login_username.focus();
			return false;
		} else if (login_password.value == "") {
			alert("密码不能为空！请重新填入！");
			login_password.focus();
			return false;
		}
		return true;
	}

	function focusOnLogin() {
		var login_username = document.getElementById("uname");
		login_username.focus();
	}
	function enterCheck(){
		if(event.keyCode == 13){
			check();
		}
	}

	function login(){
		//创建AJAX引擎
		var xmlHttp = new XMLHttpRequest();
		
		var loginUrl = "${pageContext.request.contextPath}/AdminServlet";
		var param = "action=login&username="+$("#uname").val()+"&upwd="+$("#upwd").val();
		//创建请求
		xmlHttp.open("POST", loginUrl, true);
		//发送请求
		xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded")
		xmlHttp.send(param);
		//接受响应
		xmlHttp.onreadystatechange=function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			
				if (xmlHttp.responseText == '1') {
					location.href = "${pageContext.request.contextPath}/admin/admin.jsp";
				}
				else {
					alert("用户名或者密码错误!");
				}
			}
		}
	}
</script>
</head>
<body onload="focusOnLogin()">
	<div id="main">
	<div id="login_bg">
		<div id="user_login">
			<form action="" method="post">
				
				<table  align="center" valign="center">
				<tr><td><br></td></tr>
			
				<tr>
				<td><label> 登录名 </label></td>
				<td><input type="text" id="uname" name="uname"
					value="" class="login_input" /></td>
				</tr>
				<tr>
				<td><label> 密&#160;&#160;码 </label> </td>
				<td><input
					type="password" id="upwd" name="upwd" value="" class="login_input" /></td>
				</tr>
				<tr>
				<td>&nbsp;&nbsp;<input type="button" class="login_sub" value="登录" onclick="login()" /></td>
				<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="login_sub" value="返回" onclick="javascript:history.back();"/></td>
				</tr>
				</table>
			</form>
		</div>
     </div>
	</div>

	


</body>

